package service;

import java.io.*;

/**
 * @author: jie.zhao
 * @create: 2021/03/20 20:41
 */
public class Response {

    private OutputStream outputStream;

    public Response(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public OutputStream getOutputStream() {
        return outputStream;
    }

    public void setOutputStream(OutputStream outputStream) {
        this.outputStream = outputStream;
    }

    public void outPut(String content) throws IOException {
        outputStream.write(content.getBytes());
    }

    public void outPutHtml(String path) throws IOException {
        String absulutePath = StaticResourceUtil.getAbsolutePath(path);
        File file = new File(absulutePath);
        if (file.exists() && file.isFile()){
            StaticResourceUtil.outPutResource(new FileInputStream(file),outputStream);
        }else {
            outPut(HttpProtocolUtil.getHeader400());
        }
    }


}
